package com.yami.shop.webservice.platform.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.dto.SubScribeFundsPageDTO;
import com.yami.shop.bean.enums.FundType;
import com.yami.shop.bean.model.SubscribeFundsRecord;
import com.yami.shop.bean.vo.SubScribeFundsPageVo;
import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.webservice.common.service.FundsRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资金记录Controller
 *
 * @author zhangchaoqun
 * @date 2021-10-13
 */
@RestController("AdminFundsRecordController")
@RequestMapping("/admin/fundsrecord")
@Tag(name = "admin-资金账本")
public class FundsRecordController
{
    @Autowired
    private FundsRecordService fundsRecordService;

    /**
     * 查询资金记录列表
     */
    @GetMapping("/list")
    @Operation(summary =  "资金列表", description = "获取资金列表")
    public ServerResponseEntity<PageVO<SubscribeFundsRecord>> list(PageDTO pageDTO, SubscribeFundsRecord fundsRecord)
    {
        PageVO<SubscribeFundsRecord> page = fundsRecordService.page1(pageDTO, fundsRecord);
        List<SubscribeFundsRecord> list = page.getList();
        if(list !=  null && list.size() !=0){
            List<FundType> allToList = FundType.getAllToList();
            for(SubscribeFundsRecord funds:list){
                //获取类型
                for(FundType fundType:allToList) {
                    if (funds.getType().equals(fundType.getCode())) {
                        funds.setTypeName(fundType.getInfo());
                    }
                }
                //把店铺的值赋值到用户，统一用userName 和tenantId 展示
//                if(!StringUtil.isEmpty(funds.getbCode())){
//                    funds.setUserName(funds.getbName());
//                }
//                if(funds.getTenantId()!=null){
//                    funds.setbCode(funds.getTenantId()+"");
//                }
            }
            page.setList(list);
        }
        return ServerResponseEntity.success(page);
    }
//    /**
//     * 导出资金记录列表
//     */
//    @GetMapping("/export")
//    public void export(HttpServletResponse response, FundsRecord fundsRecord) throws IOException{
//        List<FundsRecord> list = fundsRecordService.selectFundsRecordList1(fundsRecord);
//        if(list !=  null && list.size() !=0) {
//            List<FundType> allToList = FundType.getAllToList();
//            for (FundsRecord funds : list) {
//                //获取类型
//                for (FundType fundType : allToList) {
//                    if (funds.getType().equals(fundType.getCode())) {
//                        funds.setTypeName(fundType.getInfo());
//                    }
//                }
//                //把店铺的值赋值到用户，统一用userName 和tenantId 展示
//                if (!StringUtils.isEmpty(funds.getbCode())) {
//                    funds.setUserName(funds.getbName());
//                }
//                if (funds.getTenantId() != null) {
//                    funds.setbCode(funds.getTenantId() + "");
//                }
//            }
//        }
//        //第一参数:导出的模板类集合
//        //第二参数:excel中里面内容合并单元格的title
//        //第三参数:seeetName名称
//        //第四参数:导出模板实体类的class
//        //第五参数:导出文件文件名
//        //第六参数:HttpServletResponse
//        ExcelUtiles.exportExcel(list,"资金流水","资金流水列表",FundsRecord.class,"资金列表.xlsx",response);
//    }

    /**
     * 获取资金记录详细信息
     */
    @GetMapping( "/{id}")
    @Operation(summary =  "资金列表", description = "通过id查询")
    public ServerResponseEntity getInfo(@PathVariable("id") String id)
    {
        return ServerResponseEntity.success(fundsRecordService.selectFundsRecordById(id));
    }

    /**
     * 新增资金记录
     */
    @PostMapping
    @Operation(summary =  "资金列表", description = "新增")
    public ServerResponseEntity add(@RequestBody SubscribeFundsRecord fundsRecord)
    {
        return ServerResponseEntity.success(fundsRecordService.insertFundsRecord(fundsRecord));
    }

    /**
     * 修改资金记录
     */
    @PutMapping
    @Operation(summary =  "资金列表", description = "修改")
    public ServerResponseEntity edit(@RequestBody SubscribeFundsRecord fundsRecord)
    {
        return ServerResponseEntity.success(fundsRecordService.updateFundsRecord(fundsRecord));
    }

    /**
     * 删除资金记录
     */
	@DeleteMapping("/{ids}")
    @Operation(summary =  "资金列表", description = "通过id数组删除")
    public ServerResponseEntity remove(@PathVariable String[] ids)
    {
        return ServerResponseEntity.success(fundsRecordService.deleteFundsRecordByIds(ids));
    }




    @GetMapping("/page")
    @Operation(summary =  "资金列表", description = "资金列表")
    public ServerResponseEntity<IPage<SubScribeFundsPageVo>> page(PageParam<SubscribeFundsRecord> page, SubScribeFundsPageDTO dto) {
        return ServerResponseEntity.success(fundsRecordService.pageList(page, dto));
    }
}

